package com.kejiguan.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;

import com.kejiguan.ui.R;
import com.kejiguan.ui.model.SubSelectSheduleObject;

import java.util.List;

/**
 * Created by YYY on 16/8/17.
 */
public class SelectSheduleObjectSubAdapterNew extends BaseAdapter{


    private List<SubSelectSheduleObject> subSelectSheduleObjects;
    private Context context;
    private LayoutInflater layoutInflater;
    private View.OnClickListener onClickListener;

    private int selectColor,unSelectColor;

    public SelectSheduleObjectSubAdapterNew(Context context,
                                            List<SubSelectSheduleObject> subSelectSheduleObjects, View.OnClickListener onClickListener) {

        this.subSelectSheduleObjects = subSelectSheduleObjects;
        this.context=context;
        this.onClickListener=onClickListener;
        layoutInflater = LayoutInflater.from(context);

        selectColor=context.getResources().getColor(R.color.text_color2);
        unSelectColor=context.getResources().getColor(R.color.text_color1);

    }

    /**
     * 数据总数
     */
    @Override
    public int getCount() {

        if (null==subSelectSheduleObjects)
        {
            return 0;
        }
        return subSelectSheduleObjects.size();
    }

    /**
     * 获取当前数据
     */
    @Override
    public Object getItem(int position) {

        return subSelectSheduleObjects.get(position);
    }

    @Override
    public long getItemId(int position) {

        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        SubSelectSheduleObject subSelectSheduleObject=subSelectSheduleObjects.get(position);
        ViewHolder viewHolder=null;
        if (convertView == null) {

            convertView = layoutInflater
                    .inflate(R.layout.activity_select_timing_shedule_object_sub_item_layout, null);

            viewHolder=new ViewHolder();

            viewHolder.exhibitionLayout=convertView.findViewById(R.id.exhibition_layout);
            viewHolder.selectStateView= (ImageView) convertView.findViewById(R.id.select_state);
            viewHolder.nameView= (TextView) convertView.findViewById(R.id.exhibition_name);

            convertView.setTag(viewHolder);

        }else
        {
            viewHolder= (ViewHolder) convertView.getTag();
        }

        viewHolder.nameView.setText(subSelectSheduleObject.getObjectName());

        if (subSelectSheduleObject.isSelect())
        {

            viewHolder.selectStateView.setImageResource(R.mipmap.kjg_menu_checked);
            viewHolder.nameView.setTextColor(selectColor);
            viewHolder.nameView.setBackgroundResource(R.drawable.kjg_item_display_bg2);

        }else
        {

            viewHolder.selectStateView.setImageResource(R.mipmap.kjg_menu_uncheck);
            viewHolder.nameView.setTextColor(unSelectColor);
            viewHolder.nameView.setBackgroundResource(R.drawable.kjg_item_display_bg1);

        }

        if (null!=onClickListener)
        {
            viewHolder.exhibitionLayout.setTag(R.id.recyclerview_item_data,subSelectSheduleObject);
            viewHolder.exhibitionLayout.setOnClickListener(onClickListener);
        }

        return convertView;
    }

    class ViewHolder
    {
        public ImageView selectStateView;
        public TextView nameView;
        public View exhibitionLayout;
    }


}
